#include <iostream>
#include <map>
#include <string>

bool isPrime(int n) {
    if (n <= 1)
        return false;
    if (n == 2)
        return true;
    if (n % 2 == 0)
        return false;
    for (int i = 3; i * i <= n; i += 2)
        if (n % i == 0)
            return false;
    return true;
}

int findNearestPrime(int n) {
    int lower = n;
    int upper = n;
    while (true) {
        if (isPrime(lower))
            return lower;
        if (isPrime(upper))
            return upper;
        lower--;
        upper++;
    }
}

int main() {
    std::map<std::string, int> digits = {{"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4}, {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}};
    std::string input;
    getline(std::cin, input);
    std::string word;
    int number = 0;
    int count = 0;
    for (char c : input) {
        if (c == ' ') {
            if (digits.find(word) == digits.end()) {
                std::cout << "Wrong input";
                return 0;
            }
            number = number * 10 + digits[word];
            word = "";
            count++;
        } else {
            word += c;
        }
    }
    if (digits.find(word) == digits.end() || count != 2) {
        std::cout << "Wrong input";
        return 0;
    }
    number = number * 10 + digits[word];
    std::cout << findNearestPrime(number);
    return 0;
}
